home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c++
- Subject: Re: mixing static and const qualifiers for class members
- Date: 23 Mar 1996 18:06:07 GMT
- Organization: Borland International
- Message-ID: <4j1eif$dpc@druid.borland.com>
- References: <1996Mar20.143749.90333@ucl.ac.uk> <4j1327$235@coranto.ucs.mun.ca>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4j1327$235@coranto.ucs.mun.ca>, saustin@terra.nlnet.nf.ca says...
- >
- >ucecb09@ucl.ac.uk (Robert Byrne) wrote:
- >
- >>The simple way to declare integral class constants is with an enumeration.
- >>
- >>class Foo{
- >> enum constants{nPositions = 6};
- >> public:
- >> int nData[nPositions];
- >>};
- >
- >I know some compilers ( eg Borland ) allow this, but is this portable?
- >I've always cast to int in this situation:
- >
- > nt nData[int(nPositions)];
- >
- >Mind you, I've never checked on this. Am I wasting my time?
- >
- > - Steve
- >
-
- The cast is not necessary. Better yet, though, the enum hack is no longer
- necessary. You can initialize a static const int in your class declaration:
-
- class Foo{
- static const nPositions = 6;
- public:
- int nData[nPositions];
- };
-
- const Foo::nPositions;
-
- -- Pete
-
-